$(function(){

	$(".cjw").on("touchend",function(){
		var speed = 50;
		var index = 0;
		var timer = null;
		var n = Math.floor(Math.random()*8);
		var ul_li = $(".cj li");
		var arr1 = getarr();
		var names = localStorage.getItem("name");
		$.ajax({
		   type: "get",
		   url: "http://datainfo.duapp.com/lottery/fruitsubmit.php",
		   data: {userID:names,fruit:0},
		   dataType:"json",
		   success:function(data){
		    if(data==2){
		    	move();
		    	$.ajax({
				   type: "get",
				   url: "http://datainfo.duapp.com/lottery/fruitsubmit.php",
				   data: {userID:names,fruit:n+1},
				   dataType:"json",
				   success:function(data){
				   }
				});
		    }else if(data==0){
		    	alert("用户"+names+",您已经抽过奖");
		    }
		  }
		});
		
		
		function move(){
			timer = setTimeout(function(){
				speed +=50;
				
				arr1.removeClass("active");
				arr1.eq(index).addClass("active");
				index++;
				if(speed>500){
					speed=500;
				}
				if(index>7){
					index = 0;
				}
				if(index==n){
					if(speed>=500){
						alert("恭喜你中了"+(n+1)+"等奖");
						arr1.removeClass("active");
						choujiang();
					}else{
						move();
					}
				}else{
					move();
				};
				
			},speed)
		}
		function getarr(){
			var arr = [];
			arr[0] = ul_li[0];
			arr[1] = ul_li[1];
			arr[2] = ul_li[2];
			arr[3] = ul_li[5];
			arr[4] = ul_li[8];
			arr[5] = ul_li[7];
			arr[6] = ul_li[6];
			arr[7] = ul_li[3];
			return $(arr);
		}
		
		
	})
	
	choujiang();
/////////////////////获取获奖名单
  function choujiang(){
	$.ajax({
	   type: "get",
	   url: "http://datainfo.duapp.com/lottery/getsuerfr.php",
	   dataType:"jsonp",
	   success:function(data){
	     var chtml = "";
	     $.each(data,function(index){
	     	
	     	if(index<10){
	     	var date = new Date("20"+data[index].timer);
	     	var month = date.getMonth()+1;
	     	var ri = date.getDate()>9?""+date.getDate():"0"+date.getDate();
	     	var hour = date.getHours()>9?""+date.getHours():"0"+date.getHours();
	     	var min = date.getMinutes()>9?""+date.getMinutes():"0"+date.getMinutes();
	     	chtml+='<li><span class="jiang">'+data[index].fruit+'等奖</span><span class="yonghu">'+data[index].userID+'</span><span class="datetim">'+month+"月"+ri+"日  "+hour+":"+min+'</span></li>'	
	     			
	     	}
	    $(".result").html(chtml);	
	     	
	     })
	   }
	});
  }
///////////////////////////////////////退出登录
		$(".shop_car").on("touchend",function(){
			localStorage.removeItem("name");
			window.open("denglu.html","_self")
		})
		
		$(".shop_fan").on("touchend",function(){
			window.open("wdxiu.html","_self")
		})

























})
